﻿// MedicalRulesEngine.Infrastructure/Repositories/IRuleRepository.cs
using MedicalRulesEngine.Domain.Entities;

namespace MedicalRulesEngine.Infrastructure.Repositories;

/// <summary>
/// 规则仓储接口
/// 提供规则相关的特定操作
/// </summary>
public interface IRuleRepository : IRepository<MetadataRule>
{
    /// <summary>
    /// 根据工作流名称获取规则
    /// </summary>
    /// <param name="workflowName">工作流名称</param>
    /// <returns>规则集合</returns>
    Task<IEnumerable<MetadataRule>> GetByWorkflowAsync(string workflowName);

    /// <summary>
    /// 根据分类获取规则
    /// </summary>
    /// <param name="category">分类</param>
    /// <returns>规则集合</returns>
    Task<IEnumerable<MetadataRule>> GetByCategoryAsync(string category);

    /// <summary>
    /// 获取启用的规则
    /// </summary>
    /// <returns>启用的规则集合</returns>
    Task<IEnumerable<MetadataRule>> GetEnabledRulesAsync();

    /// <summary>
    /// 根据规则代码获取规则
    /// </summary>
    /// <param name="code">规则代码</param>
    /// <returns>规则对象</returns>
    Task<MetadataRule?> GetByCodeAsync(string code);

    /// <summary>
    /// 获取规则及其完整信息（包含条件、动作、标签）
    /// </summary>
    /// <param name="id">规则ID</param>
    /// <returns>完整的规则对象</returns>
    Task<MetadataRule?> GetWithDetailsAsync(string id);

    /// <summary>
    /// 搜索规则
    /// </summary>
    /// <param name="searchTerm">搜索词</param>
    /// <param name="category">分类过滤</param>
    /// <param name="isEnabled">启用状态过滤</param>
    /// <returns>符合条件的规则集合</returns>
    Task<IEnumerable<MetadataRule>> SearchRulesAsync(string? searchTerm = null,
        string? category = null, bool? isEnabled = null);

    /// <summary>
    /// 复制规则
    /// </summary>
    /// <param name="sourceRuleId">源规则ID</param>
    /// <param name="newName">新规则名称</param>
    /// <param name="newCode">新规则代码</param>
    /// <returns>复制后的规则</returns>
    Task<MetadataRule> CloneRuleAsync(string sourceRuleId, string newName, string newCode);
}

